<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="img/favicon.ico">
  <title>节点绘图类型 - Minetest Modding Books(中文版)</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="css/theme.css" />
  <link rel="stylesheet" href="css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u8282\u70b9\u7ed8\u56fe\u7c7b\u578b";
    var mkdocs_page_input_path = "7.\u8282\u70b9\u7ed8\u56fe\u7c7b\u578b.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="js/jquery-2.1.1.min.js" defer></script>
  <script src="js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="index.html" class="icon icon-home"> Minetest Modding Books(中文版)</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="./search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="index.html">首页</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="1.%E8%AF%91%E8%80%85%E5%BA%8F.html">译者序</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="2.%E5%89%8D%E8%A8%80.html">前言</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="3.%E5%85%A5%E9%97%A8.html">入门</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="4.Lua%E8%84%9A%E6%9C%AC.html">Lua脚本</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="5.%E8%8A%82%E7%82%B9%E3%80%81%E7%89%A9%E5%93%81%E5%92%8C%E5%88%B6%E4%BD%9C.html">节点、物品与制作</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="6.%E5%88%B6%E4%BD%9C%E6%9D%90%E8%B4%A8.html">制作贴图</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="7.%E8%8A%82%E7%82%B9%E7%BB%98%E5%9B%BE%E7%B1%BB%E5%9E%8B.html">节点绘图类型</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#_2">正方形节点：普通且全面</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_3">透明节点</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#glasslike_framed">Glasslike_Framed</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_4">气态节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_5">光节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_6">液体节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_7">非正方体节点</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#_8">壁挂式节点</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_9">网格节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_10">标牌节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_11">植物节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_12">火节点</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_13">更多类型</a>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html">物品栏和背包</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="9.%E5%9F%BA%E6%9C%AC%E5%9C%B0%E5%9B%BE%E6%93%8D%E4%BD%9C.html">基本地图操作</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="index.html">Minetest Modding Books(中文版)</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="index.html">Docs</a> &raquo;</li>
    
      
    
    <li>节点绘图类型</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>

          <div role="main">
            <div class="section">
              
                <h1 id="_1">节点绘图类型</h1>
<p>绘制节点的方法称为绘图类型（drawtype）。这里有许多可用的绘图类型。绘图类型的行为可以通过在节点类型定义中提供属性来控制。对于此节点的所有实例，这些属性都是固定的。可以使用<code>param2</code>来控制每个节点的一些属性。<br/>
在前面的章节中，我们已经介绍了<a href="5.%E8%8A%82%E7%82%B9%E3%80%81%E7%89%A9%E5%93%81%E5%92%8C%E5%88%B6%E4%BD%9C.html">物品和节点</a>的概念，但没有给出节点的完整定义。Minetest世界是一个三维的网格坐标。每个位置我们成为一个节点，由节点类型（名称）和两个参数（param1和param2）组成。<code>minetest.register_node</code>函数有点误导人，因为它实际上并没有注册节点—它注册了一种新类型的节点。<br/>
节点参数用于控制单独渲染节点的方式。<code>param1</code>用于存储节点的照明，<code>param2</code>的含义取决于节点类型定义的<code>paramtype2</code>属性。</p>
<h2 id="_2">正方形节点：普通且全面</h2>
<p>最普通的绘图类型就是用于渲染正方形节点的绘图类型。如果一个普通的节点的面与实体边相对，那么这一面将不会被渲染，将会导致性能大幅度提升。<br/>
<img alt="drawtype_normal" src="img/drawtype_normal.png" /><br/>
<strong>一般绘图类型</strong><br/>
相反，allfaces drawtype在向上面对实体节点时仍将渲染内侧。这适用于具有部分透明边的节点，例如叶节点。您可以使用allfaces_可选的drawtype来允许用户选择退出较慢的绘图，在这种情况下，它将像普通节点一样工作。<br/></p>
<pre><code class="language-lua">minetest.register_node(&quot;mymod:diamond&quot;, {
    description = &quot;Alien Diamond&quot;,
    tiles = {&quot;mymod_diamond.png&quot;},
    groups = {cracky = 3},
})

minetest.register_node(&quot;default:leaves&quot;, {
    description = &quot;Leaves&quot;,
    drawtype = &quot;allfaces_optional&quot;,
    tiles = {&quot;default_leaves.png&quot;}
})
</code></pre>
<p>注意：普通绘图类型是默认的绘图类型，因此不需要显式指定它。</p>
<h2 id="_3">透明节点</h2>
<p>透明节点不同于普通节点，将该类型的节点放置在普通节点节点旁边不会导致普通节点的边被隐藏。这很有用，因为透明节点往往是透明的，因此使用普通的节点将会拥有观察外界的能力。<br/>
<img alt="drawtype_glasslike_edges" src="img/drawtype_glasslike_edges.png" /><br/>
<strong>透明的边缘</strong><br/></p>
<pre><code class="language-lua">minetest.register_node(&quot;default:obsidian_glass&quot;, {
    description = &quot;Obsidian Glass&quot;,
    drawtype = &quot;glasslike&quot;,
    tiles = {&quot;default_obsidian_glass.png&quot;},
    paramtype = &quot;light&quot;,
    is_ground_content = false,
    sunlight_propagates = true,
    sounds = default.node_sound_glass_defaults(),
    groups = {cracky=3,oddly_breakable_by_hand=3},
})
</code></pre>
<h3 id="glasslike_framed">Glasslike_Framed</h3>
<p>这将使节点的边以三维效果环绕整个对象，而不是单个节点，如下所示：<br/>
<img alt="drawtype_glasslike_edges" src="img/drawtype_glasslike_framed.png" /><br/>
<strong>Glasslike_Framed的边缘</strong><br/>
你可以使用glasslike_framed_optional绘图类型来允许用户选择使用框架外观。</p>
<pre><code class="language-lua">minetest.register_node(&quot;default:glass&quot;, {
    description = &quot;Glass&quot;,
    drawtype = &quot;glasslike_framed&quot;,
    tiles = {&quot;default_glass.png&quot;, &quot;default_glass_detail.png&quot;},
    inventory_image = minetest.inventorycube(&quot;default_glass.png&quot;),
    paramtype = &quot;light&quot;,
    sunlight_propagates = true, -- Sunlight can shine through block
    groups = {cracky = 3, oddly_breakable_by_hand = 3},
    sounds = default.node_sound_glass_defaults()
})
</code></pre>
<h2 id="_4">气态节点</h2>
<p>这些节点不会渲染，因此没有纹理。</p>
<pre><code class="language-lua">minetest.register_node(&quot;myair:air&quot;, {
    description = &quot;MyAir (you hacker you!)&quot;,
    drawtype = &quot;airlike&quot;,
    paramtype = &quot;light&quot;,
    sunlight_propagates = true,

    walkable     = false, -- Would make the player collide with the air node
    pointable    = false, -- You can't select the node
    diggable     = false, -- You can't dig the node
    buildable_to = true,  -- Nodes can be replace this node.
                          -- (you can place a node and remove the air node
                          -- that used to be there)

    air_equivalent = true,
    drop = &quot;&quot;,
    groups = {not_in_creative_inventory=1}
})
</code></pre>
<h2 id="_5">光节点</h2>
<p>节点的照明存储在param1中。为了确定如何对节点的边进行着色，将使用相邻节点的灯光值。因此，实体节点没有灯光值，因为它们会遮挡灯光。<br/>
默认情况下，节点类型不允许光存储在任何节点实例中。通常需要一些节点（如玻璃和空气）能够让光线通过。为此，需要定义两个属性：</p>
<pre><code class="language-lua">paramtype = &quot;light&quot;,
sunlight_propagates = true,
</code></pre>
<p>第一行表示param1实际上存储了灯光级别。第二条线意味着太阳光应该穿过这个节点而不会降低值。</p>
<h2 id="_6">液体节点</h2>
<p>每种类型的液体都需要两个节点定义-一个用于液体源，另一个用于流动液体。</p>
<pre><code class="language-lua">-- Some properties have been removed as they are beyond
--  the scope of this chapter.
minetest.register_node(&quot;default:water_source&quot;, {
    drawtype = &quot;liquid&quot;,
    paramtype = &quot;light&quot;,

    inventory_image = minetest.inventorycube(&quot;default_water.png&quot;),
    -- ^ this is required to stop the inventory image from being animated

    tiles = {
        {
            name = &quot;default_water_source_animated.png&quot;,
            animation = {
                type     = &quot;vertical_frames&quot;,
                aspect_w = 16,
                aspect_h = 16,
                length   = 2.0
            }
        }
    },

    special_tiles = {
        -- New-style water source material (mostly unused)
        {
            name      = &quot;default_water_source_animated.png&quot;,
            animation = {type = &quot;vertical_frames&quot;, aspect_w = 16,
                aspect_h = 16, length = 2.0},
            backface_culling = false,
        }
    },

    --
    -- Behavior
    --
    walkable     = false, -- The player falls through
    pointable    = false, -- The player can't highlight it
    diggable     = false, -- The player can't dig it
    buildable_to = true,  -- Nodes can be replace this node

    alpha = 160,

    --
    -- Liquid Properties
    --
    drowning = 1,
    liquidtype = &quot;source&quot;,

    liquid_alternative_flowing = &quot;default:water_flowing&quot;,
    -- ^ when the liquid is flowing

    liquid_alternative_source = &quot;default:water_source&quot;,
    -- ^ when the liquid is a source

    liquid_viscosity = WATER_VISC,
    -- ^ how fast

    liquid_range = 8,
    -- ^ how far

    post_effect_color = {a=64, r=100, g=100, b=200},
    -- ^ colour of screen when the player is submerged
})
</code></pre>
<p>液体节点具有类似的定义，但具有不同的名称和动画。有关完整示例，请参见minetest游戏中的默认mod中的默认值：water_flowing。</p>
<h2 id="_7">非正方体节点</h2>
<p>非正方体节点允许您创建一个不是正方体的节点，而是由任意多个长方体组成的节点。<br/>
<img alt="drawtype_nodebox.gif" src="img/drawtype_nodebox.gif" /><br/>
<strong>非正方体节点</strong></p>
<pre><code class="language-lua">minetest.register_node(&quot;stairs:stair_stone&quot;, {
    drawtype = &quot;nodebox&quot;,
    paramtype = &quot;light&quot;,
    node_box = {
        type = &quot;fixed&quot;,
        fixed = {
            {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
            {-0.5, 0, 0, 0.5, 0.5, 0.5},
        },
    }
})
</code></pre>
<p>最重要的部分是节点框表：</p>
<pre><code class="language-lua">{-0.5, -0.5, -0.5,       0.5,    0,  0.5},
{-0.5,    0,    0,       0.5,  0.5,  0.5}
</code></pre>
<p>每一行是一个长方体，连接起来形成一个节点。前三个数字是最左前下角的坐标，从-0.5到0.5（含0.5），后三个数字是相反的角。它们是X，Y，Z的形式，Y在上面。<br/>
当然，如果你不想手动写xyz坐标，你可以用<a href="https://forum.minetest.net/viewtopic.php?f=14&amp;t=2840">NodeBoxEditor</a>,直接设计节点。</p>
<h3 id="_8">壁挂式节点</h3>
<p>有时你需要不同的节点板，就像火把一样被放置在地板、墙壁或天花板上。<br/></p>
<pre><code class="language-lua">minetest.register_node(&quot;default:sign_wall&quot;, {
    drawtype = &quot;nodebox&quot;,
    node_box = {
        type = &quot;wallmounted&quot;,

        -- Ceiling
        wall_top    = {
            {-0.4375, 0.4375, -0.3125, 0.4375, 0.5, 0.3125}
        },

        -- Floor
        wall_bottom = {
            {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}
        },

        -- Wall
        wall_side   = {
            {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375}
        }
    },
})
</code></pre>
<h2 id="_9">网格节点</h2>
<p>虽然节点盒通常更容易制作，但它们的局限性在于只能由长方体组成。节点框也未被选中；即使内部面完全隐藏，它们仍将被渲染。<br/>
面是网格上的平面。当两个不同节点盒的面重叠时，会出现一个内面，从而导致节点盒模型的部分不可见，但仍在渲染。<br/>
可以注册网格节点，如下所示：</p>
<pre><code class="language-lua">minetest.register_node(&quot;mymod:meshy&quot;, {
    drawtype = &quot;mesh&quot;,

    -- Holds the texture for each &quot;material&quot;
    tiles = {
        &quot;mymod_meshy.png&quot;
    },

    -- Path to the mesh
    mesh = &quot;mymod_meshy.b3d&quot;,
})
</code></pre>
<p>确保网格在模型目录中可用。大多数情况下，网格应该在模组的文件夹中，但是，可以共享另一个依赖的模组提供的网格。例如，添加更多家具类型的模组可能希望共享基本家具模组提供的模型。</p>
<h2 id="_10">标牌节点</h2>
<p>Signlike节点是平面节点，可以安装在其他节点的侧面。<br/>
尽管这个绘图类型的名字是这样的，但标志实际上并不倾向于使用标牌，而是使用<code>nodebox</code>绘图类型来提供3D效果。然而，像标志一样的拉丝类型通常被当作梯子使用。</p>
<pre><code class="language-lua">minetest.register_node(&quot;default:ladder_wood&quot;, {
    drawtype = &quot;signlike&quot;,

    tiles = {&quot;default_ladder_wood.png&quot;},

    -- Required: store the rotation in param2
    paramtype2 = &quot;wallmounted&quot;,

    selection_box = {
        type = &quot;wallmounted&quot;,
    },
})
</code></pre>
<h2 id="_11">植物节点</h2>
<p>植物节点以类似X的模式绘制其平铺。</p>
<pre><code class="language-lua">minetest.register_node(&quot;default:papyrus&quot;, {
    drawtype = &quot;plantlike&quot;,

    -- Only one texture used
    tiles = {&quot;default_papyrus.png&quot;},

    selection_box = {
        type = &quot;fixed&quot;,
        fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, 0.5, 6 / 16},
    },
})
</code></pre>
<h2 id="_12">火节点</h2>
<p>火节点类似于植物节点，只是它的设计目的是“附着”在墙壁和天花板上。
<img alt="drawtype_firelike.png" src="img/drawtype_firelike.png" /><br/>
火节点<br/></p>
<pre><code class="language-lua">minetest.register_node(&quot;mymod:clingere&quot;, {
    drawtype = &quot;firelike&quot;,

    -- Only one texture used
    tiles = { &quot;mymod:clinger&quot; },
})
</code></pre>
<h2 id="_13">更多类型</h2>
<p>这不是一个全面的列表，有更多类型包括：</p>
<ul>
<li>篱笆节点</li>
<li>根状植物节点——用于水下植物</li>
<li>铁轨节点——用于矿车轨道</li>
<li>火炬节点——用于2D墙壁/地板/顶部的节点，Minetest游戏中的火炬实际上使用了网格节点的两个不同的节点定义（default:torch和default:torch_wall）。<br/>
感兴趣的读者可以阅读一下<a href="https://rubenwardy.com/minetest_modding_book/lua_api.html#node-drawtypes">Lua API文档</a>以获得完整的列表。(API文档还没翻译，可以先阅读英文原版)</li>
</ul>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html" class="btn btn-neutral float-right" title="物品栏和背包">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="6.%E5%88%B6%E4%BD%9C%E6%9D%90%E8%B4%A8.html" class="btn btn-neutral" title="制作贴图"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    
    
      <span><a href="6.%E5%88%B6%E4%BD%9C%E6%9D%90%E8%B4%A8.html" style="color: #fcfcfc">&laquo; Previous</a></span>
    
    
      <span><a href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html" style="color: #fcfcfc">Next &raquo;</a></span>
    
  </span>
</div>
    <script>var base_url = '.';</script>
    <script src="js/theme_extra.js" defer></script>
    <script src="js/theme.js" defer></script>
      <script src="search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
